
import Modules.Account.ParentAccountDetail;
import Modules.Account.ParentAccountSummary;
import Modules.Account.ResellerAccountSummary;
import Modules.Admin.ProductsAndPrices;
import Modules.Security.Users;

import com.desidea.common.MenuConstants;
import com.desidea.utils.DirtyChecker;
import com.desidea.utils.IDirtyChecker;

import mx.controls.Alert;

private function windowInitialized():void
{
}

private function windowCreated():void
{
	loadModule();
}


public function loadModule():void{
	
	// CODE FOR DIRTY CHECK
	if( DirtyChecker.getInstance().isDirty){
		if (DirtyChecker.getInstance().sourceContainer is IDirtyChecker){
			(DirtyChecker.getInstance().sourceContainer as IDirtyChecker).promptToSave();
		}else{
			Alert.show("Save & Proceed");
		}
		return;
	}else{
		DirtyChecker.getInstance().resetDirtyChecker();
	}

	if(this.data == null){
		Alert.show("NULL DATA");
		return;
	}

	this.removeAllChildren();

	switch(String(this.data.id)){
		case MenuConstants.PARENT_ACCOUNT_SUMMARY:
			loadParentAccountSummary();
			break;
		case MenuConstants.RESELLER_ACCOUNT:
			loadResellerAccountSummary();
			break;
		case MenuConstants.PRODUCTS_PRICES:
			loadProductsAndPrices();
			break;
		case MenuConstants.USERS:
			loadUsers();
			break;
		default:
			break;
	}
}

private function loadNewParentAccount():void{
	var detail:ParentAccountDetail = new ParentAccountDetail();
	this.addChild(detail);
}
private function loadParentAccountSummary():void{
	var detail:ParentAccountSummary = new ParentAccountSummary();
	this.addChild(detail);
}
private function loadResellerAccountSummary():void{
	var detail:ResellerAccountSummary = new ResellerAccountSummary();
	this.addChild(detail);
}
private function loadProductsAndPrices():void{
	var detail:ProductsAndPrices = new ProductsAndPrices();
	this.addChild(detail);
}

private function loadUsers():void{
	var detail:Users = new Users();
	this.addChild(detail);
}
